home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / foo2lava-wrapper < prev    next >
Encoding:
Text File  |  2009-03-27  |  18.4 KB  |  725 lines

  1. #!/bin/sh
  2.  
  3. #* Copyright (C) 2003-2006  Rick Richardson
  4. #*
  5. #* This program is free software; you can redistribute it and/or modify
  6. #* it under the terms of the GNU General Public License as published by
  7. #* the Free Software Foundation; either version 2 of the License, or
  8. #* (at your option) any later version.
  9. #*
  10. #* This program is distributed in the hope that it will be useful,
  11. #* but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #* GNU General Public License for more details.
  14. #*
  15. #* You should have received a copy of the GNU General Public License
  16. #* along with this program; if not, write to the Free Software
  17. #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. #*
  19. #* Authors: Rick Richardson <rick.richardson@comcast.net>
  20.  
  21. VERSION='$Id: foo2lava-wrapper.in,v 1.36 2009/01/21 07:52:13 rick Exp $'
  22.  
  23. #
  24. # Printer Notes:
  25. #
  26. # LAVAFLOW:
  27. #    Konica Minolta 2530 DL
  28. #    Konica Minolta 2490 MF
  29. #    Xerox Phaser 6115MFP
  30. #
  31. # OPL:
  32. #    Konica Minolta 2480 MF
  33. #
  34.  
  35. PROGNAME="$0"
  36. BASENAME=`basename $PROGNAME`
  37. PREFIX=/usr
  38. SHARE=$PREFIX/share/foo2lava
  39. PATH=$PATH:/sw/bin:/opt/local/bin
  40.  
  41. #
  42. #    Log the command line, for debugging and problem reports
  43. #
  44. if [ -x /usr/bin/logger ]; then
  45.     logger -t "$BASENAME" -p lpr.info -- "foo2lava-wrapper $@" </dev/null
  46. fi
  47.  
  48. usage() {
  49.     cat <<EOF
  50. Usage:
  51.     $BASENAME [options] [ps-file]
  52.  
  53.     Foomatic printer wrapper for the foo2lava printer driver.
  54.     This script reads a Postscript ps-file or standard input
  55.     and converts it to LAVAFLOW printer format.
  56.  
  57. Normal Options:
  58. -c                Print in color (else monochrome)
  59. -C colormode      Colormode [$COLORMODE]
  60.                     1=Photos, 2=Photo and text, 3=Graphics and text
  61.                     10=ICM color profile (using -G *.icm file)
  62. -d duplex         Duplex code to send to printer [$DUPLEX]
  63.                     1=off, 2=longedge, 3=shortedge
  64. -m media          Media code to send to printer [$MEDIA]
  65.                     1=standard 4=transparency 20=thick stock 22=envelope
  66.                     23=letterhead 25=postcard 26=labels 27=recycled
  67.                     28=glossy
  68. -p paper          Paper code [$PAPER]
  69.                     1=executive 2=letter 3=legal 25=A5 26=A4 45=B5jis
  70.                     65=B5iso 80=envMonarch 81=env#10 90=envDL 91=envC5
  71.                     92=envC6 835=4x6\" 837=10x15cm
  72. -n copies         Number of copies [$COPIES]
  73. -r <xres>x<yres>  Set device resolution in pixels/inch [$RES]
  74. -s source         Source code to send to printer [$SOURCE]
  75.                     1=upper, 2=lower, 4=manual, 7=auto
  76.             Code numbers may vary with printer model.
  77. -t                Draft mode.  Every other pixel is white.
  78. -2/-3/-4/-6/-8/-10/-12/-14/-15/-16/-18
  79.                   Print with N-up (requires psutils)
  80. -o orient         For N-up: -op is portrait, -ol is landscape, -os is seascape.
  81.  
  82. Printer Tweaking Options:
  83. -u <xoff>x<yoff>  Set offset of upper left printable in pixels [varies]
  84. -l <xoff>x<yoff>  Set offset of lower right printable in pixels [varies]
  85. -L mask           Send logical clipping values from -u/-l in ZjStream [3]
  86.                   0=no, 1=Y, 2=X, 3=XY
  87. -P                Do not output START_PLANE codes.  May be needed by some
  88.                   monochrome-only printers.
  89. -X padlen         Add extra zero padding to the end of BID segments [16]
  90. -z model          Model: 0=2530DL (LAVAFLOW) or 1=2480MF (OPL) [0]
  91.  
  92. Color Tweaking Options:
  93. -g gsopts         Additional options to pass to Ghostscript, such as
  94.                   -dDITHERPPI=nnn, etc.  May appear more than once. []
  95. -G profile.icm    Convert profile.icm to a Postscript CRD using icc2ps and
  96.                   adjust colors using the setcolorrendering PS operator.
  97.                   $SHARE/icm/ will be searched for profile.icm.
  98. -I intent         Select profile intent from ICM file [$INTENT]
  99.                   0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute
  100. -G gamma-file.ps  Prepend gamma-file to the Postscript input to perform
  101.                   color correction using the setcolortransfer PS operator.
  102.  
  103. Debugging Options:
  104. -S plane          Output just a single color plane from a color print [all]
  105.                   1=Cyan, 2=Magenta, 3=Yellow, 4=Black
  106. -D lvl            Set Debug level [$DEBUG]
  107. -V                $VERSION
  108. EOF
  109.  
  110.     exit 1
  111. }
  112.  
  113. #
  114. #       Report an error and exit
  115. #
  116. error() {
  117.     echo "$BASENAME: $1" >&2
  118.     exit 1
  119. }
  120.  
  121. dbgcmd() {
  122.     if [ $DEBUG -ge 1 ]; then
  123.         echo "$@" >&2
  124.     fi
  125.     "$@"
  126. }
  127.  
  128. #
  129. #    N-up-ify the job.  Requires psnup from psutils package
  130. #
  131. nup() {
  132.     case "$NUP" in
  133.     [2368]|1[0458])
  134.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
  135.     ;;
  136.     [49]|1[26])
  137.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
  138.     ;;
  139.     *)
  140.     error "Illegal call to nup()."
  141.     ;;
  142.     esac
  143. }
  144.  
  145. #
  146. #       Process the options
  147. #
  148.  
  149. # Try to use a local copy of GhostScript 8.14, if available.  Otherwise,
  150. # fallback to whatever the Linux distro has installed (usually 7.05)
  151. #
  152. # N.B. := operator used here, when :- would be better, because "ash"
  153. # doesn't have :-
  154. if gs.foo -v >/dev/null 2>&1; then
  155.         GSBIN=${GSBIN:-gs.foo}
  156. else
  157.         GSBIN=${GSBIN:-gs}
  158. fi
  159.  
  160. CMDLINE="$*"
  161. DEBUG=0
  162. DUPLEX=1
  163. COLOR=
  164. COLORMODE=default
  165. MODEL=0
  166. QUALITY=1
  167. QUALITY=wts
  168. MEDIA=0
  169. COPIES=1
  170. test -r /etc/papersize && PAPER=$(cat /etc/papersize)
  171. test "$PAPER" || PAPER=2
  172. RES=1200x600
  173. SOURCE=255
  174. NUP=
  175. CLIP_UL=
  176. CLIP_LR=
  177. CLIP_LOG=
  178. BC=
  179. AIB=
  180. NOPLANES=
  181. COLOR2MONO=
  182. GAMMAFILE=default
  183. INTENT=0
  184. GSOPTS=
  185. EXTRAPAD=
  186. SAVETONER=
  187. NUP_ORIENT=
  188. GSDEV=-sDEVICE=pbmraw
  189. # What mode to use if the user wants us to pick the "best" mode
  190. case `$GSBIN --version` in
  191. 7*)    DEFAULTCOLORMODE=10
  192.     DEFAULTCOLORMODE=2
  193.     DEFAULTCOLORMODE=10
  194.     ;;
  195. 8.1*)
  196.     QUALITY=1
  197.         DEFAULTCOLORMODE=10
  198.         ;;
  199. *)    DEFAULTCOLORMODE=2
  200.     DEFAULTCOLORMODE=10
  201.     ;;
  202. esac
  203. while getopts "1:23456789o:b:cC:d:g:l:u:L:m:n:p:q:r:s:tz:ABS:D:G:I:PX:Vh?" opt
  204. do
  205.     case $opt in
  206.     b)    GSBIN="$OPTARG";;
  207.     c)    COLOR=-c;;
  208.     d)    DUPLEX="$OPTARG";;
  209.     g)    GSOPTS="$GSOPTS $OPTARG";;
  210.     m)    MEDIA="$OPTARG";;
  211.     n)    COPIES="$OPTARG";;
  212.     p)    PAPER="$OPTARG";;
  213.     q)    QUALITY="$OPTARG";;
  214.     r)    RES="$OPTARG";;
  215.     s)    SOURCE="$OPTARG";;
  216.     t)    SAVETONER="-t";;
  217.     z)    MODEL="$OPTARG";;
  218.     l)    CLIP_LR="-l $OPTARG";;
  219.     u)    CLIP_UL="-u $OPTARG";;
  220.     L)    CLIP_LOG="-L $OPTARG";;
  221.     A)    AIB=-A;;
  222.     B)    BC=-B;;
  223.     C)    COLORMODE="$OPTARG";;
  224.     S)    COLOR2MONO="-S$OPTARG";;
  225.     D)    DEBUG="$OPTARG";;
  226.     G)    GAMMAFILE="$OPTARG";;
  227.     I)    INTENT="$OPTARG";;
  228.     P)    NOPLANES=-P;;
  229.     X)    EXTRAPAD="-X $OPTARG";;
  230.     [234689])    NUP="$opt";;
  231.     [57])    error "Can't find acceptable layout for $opt-up";;
  232.     1)    case "$OPTARG" in
  233.         [024568])    NUP="1$OPTARG";;
  234.         *)    error "Can't find acceptable layout for 1$OPTARG-up";;
  235.         esac
  236.         ;;
  237.     o)    case "$OPTARG" in
  238.         l*)    NUP_ORIENT=-l;;
  239.         s*)    NUP_ORIENT=-r;;
  240.         p*|*)    NUP_ORIENT=;;
  241.         esac;;
  242.     V)    echo "$VERSION"; foo2lava -V; foo2zjs-pstops -V; exit 0;;
  243.     h|\?)
  244.         if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
  245.             echo "Illegal command:"
  246.             echo "    $0 $CMDLINE"
  247.             echo
  248.         fi
  249.         usage;;
  250.     esac
  251. done
  252. shift `expr $OPTIND - 1`
  253.  
  254. #
  255. # If there is an argument left, take it as the file to print.
  256. # Else, the input comes from stdin.
  257. #
  258. if [ $# -ge 1 ]; then
  259.     if [ "$LPJOB" = "" ]; then
  260.     : # LPJOB="$1"
  261.     fi
  262.     exec < $1
  263. fi
  264.  
  265.  
  266. #
  267. #    Select the ghostscript device to use
  268. #
  269. if [ "" = "$COLOR" ]; then
  270.     GSDEV=-sDEVICE=pbmraw
  271. else
  272.     GSDEV=-sDEVICE=bitcmyk
  273. fi
  274. case "$GAMMAFILE" in
  275. default)
  276.     GAMMAFILE=km2530-jconner-d50.icm
  277.     ;;
  278. none) GAMMAFILE=;;
  279. esac
  280.  
  281. #
  282. case "$QUALITY" in
  283. 0)
  284.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  285.     ;;
  286. 1)
  287.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  288.     ;;
  289. 2)
  290.     GSOPTS="-dMaxBitmap=500000000 $GSOPTS"
  291.     ;;
  292. wts)
  293.     GSOPTS="-dCOLORSCREEN -dMaxBitmap=500000000 $GSOPTS"
  294.     ;;
  295. esac
  296.  
  297. #
  298. #    Validate model code
  299. #
  300. case "$MODEL" in
  301. 0|1)    ;;
  302. *)    error "Unknown model code $MODEL";;
  303. esac
  304.  
  305. #
  306. #    Validate media code
  307. #
  308. case "$MEDIA" in
  309. 0|plain)    MEDIA=0; if [ $MODEL = 1 ]; then MEDIA=plain; fi;;
  310. 4|transparency)    MEDIA=4; if [ $MODEL = 1 ]; then MEDIA=transparency; fi;;
  311. 20|thickstock)    MEDIA=20; if [ $MODEL = 1 ]; then MEDIA=cardstock; fi;;
  312. 22|envelope)    MEDIA=22; if [ $MODEL = 1 ]; then MEDIA=envelope; fi;;
  313. 23|letterhead)    MEDIA=23; if [ $MODEL = 1 ]; then MEDIA=stationery-letterhead; fi;;
  314. 25|postcard)    MEDIA=25; if [ $MODEL = 1 ]; then MEDIA=photographic-matte; fi;;
  315. 26|labels)    MEDIA=26; if [ $MODEL = 1 ]; then MEDIA=labels; fi;;
  316. 27|recycled)    MEDIA=27; if [ $MODEL = 1 ]; then MEDIA=plain; fi;;
  317. 28|glossy)    MEDIA=28; if [ $MODEL = 1 ]; then MEDIA=photographic-glossy; fi;;
  318. [0-9]*)        ;;
  319. *)        error "Unknown media code $MEDIA";;
  320. esac
  321.  
  322. #
  323. #    Validate source (InputSlot) code
  324. #
  325. case "$SOURCE" in
  326. 1|tray1)    SOURCE=1;;
  327. 4|tray2)    SOURCE=4;;
  328. 255|auto)    SOURCE=255;;
  329. [0-9]*)        ;;
  330. *)        error "Unknown source code $SOURCE";;
  331. esac
  332.  
  333. #
  334. #    Validate Duplex code
  335. #
  336. case "$DUPLEX" in
  337. 1|off|none)    DUPLEX=1;;
  338. 2|long*)    DUPLEX=2;;
  339. 3|short*)    DUPLEX=3;;
  340. [0-9]*)        ;;
  341. *)        error "Unknown duplex code $DUPLEX";;
  342. esac
  343.  
  344. #
  345. #    Validate Resolution
  346. #
  347. case "$RES" in
  348. 600x600)    ;;
  349. 1200x600)    ;;
  350. 2400x600)    ;;
  351. *)        error "Illegal resolution $RES";;
  352. esac
  353.  
  354. #
  355. #    Figure out the paper dimensions in pixels/inch, and set the
  356. #    default clipping region.  Unfortunately, this is a trouble
  357. #    area for ZjStream printers.  Various versions of ZjS print
  358. #    engines react differently when asked to print into their
  359. #    unprintable regions.
  360. #
  361. set_clipping() {
  362.     ulx=$1; uly=$2
  363.     lrx=$3; lry=$4
  364.  
  365.     # Set clipping region if it isn't already set
  366.     if [ "$CLIP_UL" = "" ]; then
  367.     case "$RES" in
  368.     600x600)    ulx=`expr $ulx / 2`;;
  369.     2400x600)    ulx=`expr $ulx \* 2`;;
  370.     esac
  371.     CLIP_UL="-u ${ulx}x${uly}"
  372.     fi
  373.     if [ "$CLIP_LR" = "" ]; then
  374.     case "$RES" in
  375.     600x600)    lrx=`expr $lrx / 2`;;
  376.     2400x600)    lrx=`expr $lrx \* 2`;;
  377.     esac
  378.     CLIP_LR="-l ${lrx}x${lry}"
  379.     fi
  380. }
  381.  
  382. case "$PAPER" in
  383. Custom*)
  384.         case "$PAPER" in
  385.         Custom\.[0-9]*\x[0-9]*)
  386.             XDIM=`echo "$PAPER" | sed -e 's/Custom\.//' -e 's/x.*//'`
  387.             YDIM=`echo "$PAPER" | sed -e 's/Custom\.//' -e 's/.*x//'`
  388.             ;;
  389.         *)
  390.         #%%BeginFeature: *CustomPageSize True
  391.         #216
  392.         #360
  393.         #0
  394.         #0
  395.         #0
  396.         #pop pop pop pop pop
  397.  
  398.         #%%BeginFeature: *CustomPageSize True
  399.         #792.000000 612.000000 1 0.000000 0.000000
  400.         #pop pop pop pop pop
  401.  
  402.         if [ $DEBUG = 0 ]; then
  403.             TMPFILE=/tmp/cus$$
  404.         else
  405.             TMPFILE=/tmp/custom.ps
  406.         fi
  407.         cat >$TMPFILE
  408.         exec <$TMPFILE
  409.  
  410.         tmp=`head -n 10000 $TMPFILE \
  411.             | sed -n '/CustomPageSize/{n;p;n;p;}' \
  412.             | tr '\n' ' '`
  413.         case "$tmp" in
  414.         [0-9]*\ [0-9]*)
  415.             XDIM=`echo "$tmp" | sed 's/ .*//'`
  416.             YDIM=`echo "$tmp" | sed -e 's/^[^ ]* //' -e 's/ .*//'`
  417.             ;;
  418.         *)
  419.             if [ $DEBUG = 0 ]; then rm -f $TMPFILE; fi
  420.             error "Custom page size [XY]DIM != 1-99999"
  421.             ;;
  422.         esac
  423.         ;;
  424.         esac
  425.         xmm=`dc -e "$XDIM 25.4 * 36 + 72/p"`
  426.         XDIM=`dc -e "$XDIM 1200* 72/p"`
  427.         ymm=`dc -e "$YDIM 25.4 * 36 + 72/p"`
  428.         YDIM=`dc -e "$YDIM 600* 72/p"`
  429.         PAPER=101;        paper=letter;
  430.         MEDIA=20
  431.                 set_clipping 2 100     2 100
  432.         if [ $MODEL = 1 ]; then PAPER=custom_size_${xmm}x${ymm}mm; fi
  433.         ;;
  434. 1|executive)    PAPER=1;    paper=executive; XDIM="8700";  YDIM="6300"
  435.         set_clipping 206 110    206 110
  436.         if [ $MODEL = 1 ]; then PAPER=na_executive_7.25x10.5in; fi
  437.         ;;
  438. 2|letter)    PAPER=2;    paper=letter;    XDIM="10200"; YDIM="6600"
  439.         set_clipping 204 100    204 100
  440.         if [ $MODEL = 1 ]; then PAPER=na_letter_8.5x11in; fi
  441.         ;;
  442. 3|legal)    PAPER=3;    paper=legal;     XDIM="10200"; YDIM="8400"
  443.         set_clipping 204 104    204 104
  444.         if [ $MODEL = 1 ]; then PAPER=na_legal_8.5x14in; fi
  445.         ;;
  446. 25|a5|A5)    PAPER=25;    paper=a5;        XDIM="6992";  YDIM="4960"
  447.         set_clipping 216 112    216 112
  448.         if [ $MODEL = 1 ]; then PAPER=iso_a5_148x210mm; fi
  449.         ;;
  450. 26|a4|A4)    PAPER=26;    paper=a4;        XDIM="9920";  YDIM="7016"
  451.         set_clipping 208 100    208 100
  452.         if [ $MODEL = 1 ]; then PAPER=iso_a4_210x297mm; fi
  453.         ;;
  454. 45|b5jis|B5jis)    PAPER=45;    paper=b5;        XDIM="8598";  YDIM="6070"
  455.         set_clipping 204 107    202 107
  456.         if [ $MODEL = 1 ]; then PAPER=jis_b5_182x257mm; fi
  457.         ;;
  458. 65|b5iso|B5iso)    PAPER=65;    paper=b5;        XDIM="8314";  YDIM="5906"
  459.         set_clipping 206 105    204 105
  460.         ;;
  461. 80|envMonarch)    PAPER=80;    paper=envMonarch;XDIM="4650";  YDIM="4500"
  462.         set_clipping 214 106    212 106
  463.         if [ $MODEL = 1 ]; then PAPER=na_monarch_3.875x7.5in; fi
  464.         ;;
  465. 81|"env#10")    PAPER=81;    paper=env10;     XDIM="4950";  YDIM="5700"
  466.         set_clipping 204 114    202 114
  467.         if [ $MODEL = 1 ]; then PAPER=na_number-10_4.125x9.5in; fi
  468.         ;;
  469. 90|envDL)    PAPER=90;    paper=envDL;     XDIM="5200";  YDIM="5200"
  470.         set_clipping 216 104    216 104
  471.         if [ $MODEL = 1 ]; then PAPER=iso_dl_110x220mm; fi
  472.         ;;
  473. 91|envC5)    PAPER=91;    paper=envC5;     XDIM="7650";  YDIM="5408"
  474.         set_clipping 210 112    208 112
  475.         if [ $MODEL = 1 ]; then PAPER=iso_c5_162x229mm; fi
  476.         ;;
  477. 92|envC6)    PAPER=92;    paper=envC6;     XDIM="5386";  YDIM="3826"
  478.         set_clipping 214 105    212 105
  479.         if [ $MODEL = 1 ]; then PAPER=iso_c6_114x162mm; fi
  480.         ;;
  481. 835|photo4x6)    PAPER=835;    paper=photo4x6;  XDIM="4800";  YDIM="3600"
  482.         set_clipping 224 104    224 104
  483.         ;;
  484. 837|photo10x15)    PAPER=837;    paper=photo10x15; XDIM="4818";  YDIM="3590"
  485.         # Actually, 102x152
  486.         set_clipping 201 115    201 115
  487.         ;;
  488. *)        error "Unimplemented paper code $PAPER";;
  489. esac
  490. # e.g. /usr/share/ghostscript/7.07/lib/gs_statd.ps
  491. PAPERSIZE="-sPAPERSIZE=$paper";
  492.  
  493. case "$RES" in
  494. 600x600)    XDIM=`expr $XDIM / 2`;;
  495. 1200x600)    ;;
  496. 2400x600)    XDIM=`expr $XDIM \* 2`;;
  497. esac
  498. DIM="${XDIM}x${YDIM}"
  499.  
  500. #
  501. # Filter thru psnup if N-up printing has been requested
  502. #
  503. case $NUP in
  504. [234689]|1[024568])    PREFILTER="nup";;
  505. *)            PREFILTER=cat;;
  506. esac
  507. if [ "$DEBUG" -ge 9 ]; then
  508.     PREFILTER="tee /tmp/$BASENAME.ps"
  509. fi
  510.  
  511. #
  512. #    Overload -G.  If the file name ends with ".icm" or ".ICM"
  513. #    then convert the ICC color profile to a Postscript CRD,
  514. #    then prepend it to the users job.  Select the intent
  515. #    using the -I option.
  516. #
  517.  
  518. create_crd() {
  519.     #
  520.     # Create a Postscript CRD
  521.     #
  522.     ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
  523.     if [ -x $ICC2PS ]; then
  524.         case "$GAMMAFILE" in
  525.         none.icm | */none.icm)
  526.             ;;
  527.         *)
  528.             $ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
  529.                 || error "Problem converting .ICM file to Postscript"
  530.             ;;
  531.         esac
  532.  
  533.     PSTOPS_OPTS="$PSTOPS_OPTS -c"
  534.         cat > $ICCTMP.usecie.ps <<-EOF
  535.                 %!PS-Adobe-3.0
  536.                 <</UseCIEColor true>>setpagedevice
  537.     EOF
  538.         if [ "$QUALITY" = wts ]; then
  539.             cat >> $ICCTMP.usecie.ps <<-EOF
  540.                 << /UseWTS true >> setuserparams
  541.                 <<
  542.                     /AccurateScreens true
  543.                     /HalftoneType 1
  544.                     /HalftoneName (Round Dot Screen) cvn
  545.                     /SpotFunction { 180 mul cos exch 180 mul cos add 2 div}
  546.                     /Frequency 137
  547.                     /Angle 37
  548.                 >> sethalftone
  549.         EOF
  550.         fi
  551.         cat > $ICCTMP.selcrd.ps <<-EOF
  552.                 /Current /ColorRendering findresource setcolorrendering
  553.     EOF
  554.         case "$GAMMAFILE" in
  555.         none.icm | */none.icm) GAMMAFILE="$ICCTMP.usecie.ps";;
  556.         *)      GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps";;
  557.         esac
  558.     else
  559.         GAMMFILE=
  560.     fi
  561. }
  562.  
  563. if [ $DEBUG -gt 0 ]; then
  564.     ICCTMP=/tmp/icc
  565. else
  566.     ICCTMP=/tmp/icc$$
  567. fi
  568.  
  569. if [ "" = "$COLOR" ]; then
  570.     COLORMODE=
  571.     GAMMAFILE=
  572. else
  573.     case "$COLORMODE" in
  574.     default)    COLORMODE=$DEFAULTCOLORMODE;;
  575.     esac
  576. fi
  577.  
  578. CRDBASE="$PREFIX/share/foo2zjs/crd"
  579. case "$RES" in
  580.     600x600)    SCREEN=screen1200.ps;;
  581.     1200x600)    SCREEN=screen1200.ps;;
  582.     2400x600)    SCREEN=screen2400.ps;;
  583. esac
  584.  
  585. PSTOPS_OPTS="-n"
  586.  
  587. case "$COLORMODE" in
  588. 0|"")
  589.     # Monochrome
  590.     ;;
  591. 10|icm)
  592.     # Use old ICM method
  593.     AIB=-A
  594.     BC=-B
  595.     case "$GAMMAFILE" in
  596.     none.icm | */none.icm)
  597.         create_crd
  598.         ;;
  599.     *.icm|*.ICM|*.icc|*.ICC)
  600.     #
  601.     # Its really an .ICM file, not a gamma file.
  602.     #
  603.     # The file can be a full path name, or the name of a file in $SHARE/icm/
  604.     #
  605.     if [ -r "$GAMMAFILE" ]; then
  606.         create_crd
  607.     elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
  608.         GAMMAFILE="$SHARE/icm/$GAMMAFILE"
  609.         create_crd
  610.     else
  611.         GAMMAFILE=
  612.     fi
  613.     ;;
  614.     esac
  615.     ;;
  616. 1|photo)
  617.     # Photo
  618.     GAMMAFILE="$CRDBASE/prolog.ps"
  619.     GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr125,75-per.crd"
  620.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  621.     ;;
  622. 2|graphics)
  623.     # Photo and Text
  624.     GAMMAFILE="$CRDBASE/prolog.ps"
  625.     #GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,75-per.crd"
  626.     GAMMAFILE="$GAMMAFILE $CRDBASE/kh.crd"
  627.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  628.     ;;
  629. 3|text)
  630.     # Graphic and Text
  631.     GAMMAFILE="$CRDBASE/prolog.ps"
  632.     #GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,50-per.crd"
  633.     GAMMAFILE="$GAMMAFILE $CRDBASE/kx.crd"
  634.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  635.     ;;
  636. 4|tonersave)
  637.     # Reduced toner
  638.     GAMMAFILE="$CRDBASE/prolog.ps"
  639.     GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,0-per.crd"
  640.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  641.     ;;
  642. *.crd)
  643.     GAMMAFILE="$CRDBASE/prolog.ps"
  644.     if [ -f $COLORMODE ]; then
  645.     GAMMAFILE="$GAMMAFILE $COLORMODE"
  646.     elif [ -f $CRDBASE/$COLORMODE ]; then
  647.     GAMMAFILE="$GAMMAFILE $CRDBASE/$COLORMODE"
  648.     else
  649.     error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
  650.     fi
  651.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  652.     ;;
  653. *)
  654.     error "Unknown color method '$COLORMODE'"
  655.     ;;
  656. esac
  657.  
  658. if [ "$COLOR" != "" -a "$QUALITY" = wts ]; then
  659.     PSTOPS_OPTS="$PSTOPS_OPTS -w"
  660. fi
  661.  
  662. if [ "" != "$COLOR" ]; then
  663.     if [ "" = "$AIB" -a "" = "$BC" ]; then
  664.     # Faster, but can't handle AllIsBlack or BlackClears
  665.     : #GSDEV=-sDEVICE=pksmraw
  666.     else
  667.     # Can't handle different size pages
  668.     : #GSDEV=-sDEVICE=bitcmyk
  669.     fi
  670. fi
  671.  
  672. #
  673. #    Figure out USERNAME
  674. #
  675. if [ "$LPUSER" != "" ]; then
  676.     USER="$LPUSER@$LPHOST"
  677. else
  678.     USER=""
  679. fi
  680.  
  681. #
  682. #    Main Program, just cobble together the pipeline and run it
  683. #
  684. #    The malarky with file descriptors 1 and 3 is to avoid a bug in
  685. #    (some versions?) of Ghostscript where Postscript's stdout gets
  686. #    intermingled with the printer drivers output, resulting in
  687. #    corrupted image data.
  688. #
  689. GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
  690.  
  691. foo2zjs-pstops $PSTOPS_OPTS | \
  692. $PREFILTER \
  693. | ($GS $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS \
  694.     -sOutputFile="|cat 1>&3" $GAMMAFILE -_ >/dev/null) 3>&1 \
  695. | foo2lava -r$RES -g$DIM -p$PAPER -m$MEDIA -n$COPIES -d$DUPLEX -s$SOURCE \
  696.         -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG $SAVETONER \
  697.         -J "$LPJOB" -U "$USER" \
  698.         $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD -D$DEBUG
  699.  
  700. #
  701. #    Log the command line, for debugging and problem reports
  702. #
  703. if [ -x /usr/bin/logger ]; then
  704.     logger -t "$BASENAME" -p lpr.info -- \
  705.     "$GSBIN $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS $GAMMAFILE"
  706.     logger -t "$BASENAME" -p lpr.info -- \
  707.     "foo2lava -r$RES -g$DIM -p$PAPER -m$MEDIA \
  708. -n$COPIES -d$DUPLEX -s$SOURCE -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG \
  709. $SAVETONER $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD"
  710. fi
  711.  
  712. #
  713. #    Remove cruft
  714. #
  715. if [ $DEBUG -eq 0 ]; then
  716.     for i in crd.ps log usecie.ps selcrd.ps
  717.     do
  718.     file="$ICCTMP.$i"
  719.     [ -f $file ] && rm -f $file
  720.     done
  721.     [ -f "$TMPFILE" ] && rm -f $TMPFILE
  722. fi
  723.  
  724. exit 0
  725.